<template>
  <div class="toggle_controls">
    <button class="toggle_btn" @click="toggle_layer('vector')">
      <img
        src="/src/assets/imgs/vector.png"
        alt="矢量图层"
        class="toggle_img"
        title="矢量图层"
      />
    </button>
    <button class="toggle_btn" @click="toggle_layer('image')">
      <img
        src="/src/assets/imgs/image.png"
        alt="影像图层"
        class="toggle_img"
        title="影像图层"
      />
    </button>
  </div>
</template>

<script setup>
import { useLayerStore } from "../stores";
const layerStore = useLayerStore(); // layerStore.base_layer具有响应式
// console.log(layerStore);
const { toggle_base_layer } = layerStore;
// console.log(base_layer, toggle_base_layer);
const $gaode_vector = inject("$gaode_vector");
const $gaode_image = inject("$gaode_image");
onMounted(() => {
  const $map = inject("$map");
  // console.log($map);
});
function toggle_layer(index) {
  if (index === "vector") {
    $gaode_vector.setVisible(true);
    $gaode_image.setVisible(false);
    toggle_base_layer('vec')
  } else {
    $gaode_vector.setVisible(false);
    $gaode_image.setVisible(true);
    toggle_base_layer('img')
  }
}
</script>

<style lang="scss" scoped>
.toggle_controls {
  position: fixed;
  bottom: 20px;
  right: 20px;
}
.toggle_btn {
  width: 50px;
  height: 50px;
  cursor: pointer;
  // border: none;
  border: 1px solid #eee;
  border-radius: 50%;
  overflow: hidden;
  .toggle_img {
    vertical-align: bottom;
    width: 100%;
    height: 100%;
  }
  &:not(&:first-child) {
    margin-left: 10px;
  }
}
</style>
